/**
 * @Classname send
 * @Description TODO
 * @Date 2021/4/30 11:09
 * @Created by GUOCHEN
 */

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/04/30 11:09
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class Send {

    public static final Logger LOGGER = LoggerFactory.getLogger(Send.class);

    @Autowired
    DefaultMQProducer defaultMQProducer;

    @SneakyThrows
    @Test
    public void name() {
        String msg = "hhahahahhahhaha";

        LOGGER.info("发送MQ消息内容：" + msg);
        Message sendMsg = new Message("TestTopic", "TestTag", msg.getBytes());
        // 默认3秒超时
        SendResult sendResult = defaultMQProducer.send(sendMsg);
        LOGGER.info("消息发送响应：" + sendResult.toString());

    }

}
